home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 April
/
EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso
/
internet
/
others
/
spoolwatch.lha
/
SpoolWatch
/
Src
/
GetDest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-15
|
2KB
|
83 lines
/*
* Function GetDest
* Programmer N.d'Alterio
* Date 12/09/95
*
* Synopsis: Gets a string of length up to MAX_DEST_LEN from the
* msg from the first line which has type as its 1st
* character. The string contains the 2nd word on that
* line. If the character is not found in MAX_HEADER_LINES
* then an error code is returned.
*
* Arguments: filename File to scan
* type N or T for news or mail
* dest String to return destination in
*
* Returns: 0 If normal exit
* >0 If error
*
* Variables: ch Temp variable
* rcode Return code
* done Loop flag
* line Count of number of lines
* fptr file handle
*
* Functions: fopen Open file (ANSI)
* fclose Close file (ANSI)
* fgetc Get char (ANSI)
* fgets Get string (ANSI)
* fscanf Read input (ANSI)
*
* $Id: GetDest.c 1.3 1995/09/15 22:15:04 daltern Exp $
*
*/
#include "SpoolWatch.h"
#define MAX_HEADER_LINES 50
int GetDest( char *filename, char type, char *dest )
{
int rcode = 0;
int done = FALSE;
int lines = 0;
int ch = 0;
FILE *fptr;
if ( fptr = fopen( filename, "r" ) ) {
while ( !done && ( ch != EOF ) && ( lines < MAX_HEADER_LINES ) ) {
if ( ( ch = fgetc( fptr ) ) == type ) {
fscanf( fptr, "%*s" );
fgets( dest, (MAX_DEST_LEN-1), fptr );
done = TRUE;
} else {
while ( ( ( ch = fgetc( fptr ) ) != '\n' ) && ( ch != EOF ) ) {}
lines++;
} /* end if : find line starting with type */
} /* end while */
fclose( fptr );
if ( ( ch == EOF ) || ( lines == MAX_HEADER_LINES ) ) rcode = 10;
} /* end if */
return rcode;
} /* end function GetDest */
/*========================================================================*
END FUNCTION GetDest
*========================================================================*/